package com.ruoyi.project.cltmanage.charge.controller;

import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.project.cltmanage.charge.service.IChargeService;

import com.ruoyi.project.cltmanage.domain.CltCharge;

import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/cltmanage/charge")
public class ChargeController {
    @Autowired
    private IChargeService iChargeService;


    @PreAuthorize("@ss.hasPermi('cltmanage:charge:list')")
    @GetMapping("/selectID/{regId}")
    public AjaxResult selectID ( @PathVariable String regId){

        List<CltCharge> dctCharges= iChargeService.selectID(regId);
        List<?> list = dctCharges;
        return AjaxResult.success(dctCharges);
    }


    @PreAuthorize("@ss.hasPermi('cltmanage:charge:list')")
    @GetMapping("/selectCum")
    public AjaxResult selectCost (String cost){
        Integer co = Integer.parseInt(cost);
        List<CltCharge> dctCharges= iChargeService.selectCost(co);
        return AjaxResult.success(dctCharges);
    }

    @PreAuthorize("@ss.hasPermi('cltmanage:charge:list')")
    @GetMapping("/selectNum/{type}/{dctOrderId}")
    public AjaxResult selectNum(@PathVariable String type ,@PathVariable String dctOrderId){
        Integer co = Integer.parseInt(type);
//        System.out.println(type);
//        System.out.println(dctOrderId);
        System.out.println(iChargeService.selectNum(co,dctOrderId).toString());
        List<CltCharge> dctCharges= iChargeService.selectNum(co,dctOrderId);
        return AjaxResult.success(dctCharges);
    }


    @PreAuthorize("@ss.hasPermi('cltmanage:charge:list')")
    @GetMapping("/selectOne")
    public AjaxResult selectOne(){
        List<CltCharge> dctCharges= iChargeService.selectOne();
        return AjaxResult.success(dctCharges);
    }

    @PreAuthorize("@ss.hasPermi('cltmanage:charge:list')")
    @GetMapping("/updateCash/{id}")
    public AjaxResult updateCash(@PathVariable String[] id ){
        for (String id1:id) {
            int f = iChargeService.updateCash(id1);
            if (f==0){
                return AjaxResult.success("0");
            }

        }
//        System.out.println(type);
//        System.out.println(dctOrderId);
        return AjaxResult.success("1");
    }
    @PreAuthorize("@ss.hasPermi('cltmanage:charge:list')")
    @GetMapping("/updateWeb/{id}")
    public AjaxResult updateWeb(@PathVariable String[] id ){
        for (String id1:id) {
            int f = iChargeService.updateWeb(id1);
            if (f==0){
                return AjaxResult.success("0");
            }

        }
//        System.out.println(type);
//        System.out.println(dctOrderId);
        return AjaxResult.success("1");
    }

}
